% ************************************************************* %
% **************** HF_MMSE_Synch_Fractional ************************ %
% ************************************************************* %


function [OUT_Symbols] = HF_MMSE_Synch(RX_IN_Filtered_out, Original_RX_IN, Start, Original_Start_used,...
    Data_Length, estimation_length, ChLength, N1, N2, N, Oversample, EsNoRatio)

Filter_Length = 12;
Rolloff = 0.385;
HF_SRRC = rcosfir(Rolloff,Filter_Length/2,Oversample,1,'sqrt');
HF_SRRC_TX_RX = conv(HF_SRRC,HF_SRRC);

MiniProbe_Plus = RX_IN_Filtered_out(Start + 1 : Start + 31*Oversample);
Middle_Probe = RX_IN_Filtered_out(Start + 31*Oversample + 1 : Start + (31+41)*Oversample);
MiniProbe_Minus = RX_IN_Filtered_out(Start + (31+41)*Oversample + 1 : Start + (31+41+31)*Oversample);

Actual_MiniProbe_Plus = Original_RX_IN(Original_Start_used + 1 : Original_Start_used + 31*Oversample);
Actual_Middle_Probe = Original_RX_IN(Original_Start_used + 31*Oversample + 1 : Original_Start_used + (31+41)*Oversample);
Actual_MiniProbe_Minus = Original_RX_IN(Original_Start_used + (31+41)*Oversample + 1 : Original_Start_used + (31+41+31)*Oversample);

IN_Frame_toEqualizer = [MiniProbe_Plus(end-N2*Oversample+1-3:end), Middle_Probe, MiniProbe_Minus(1:N1*Oversample)];

Hard_Decision_Symbols = Actual_MiniProbe_Plus(end-N2:end);
Hard_Decision_Symbols_Samples1 = conv(upsample(Hard_Decision_Symbols,Oversample), HF_SRRC_TX_RX);
Hard_Decision_Symbols_Samples = Hard_Decision_Symbols_Samples1(length(HF_SRRC)+Oversample:end-length(HF_SRRC)+1);

[Chest_Plus Error_Plus] = HF_LSChEstimateSubtacting(MiniProbe_Plus(end - estimation_length +1 : end), Actual_MiniProbe_Plus(end - estimation_length +1 : end), ChLength);
Chest_Plus = Chest_Plus(1,1:21).';

[Chest_Minus Error_Minus] = HF_LSChEstimateSubtacting(MiniProbe_Minus(end - estimation_length +1 : end), Actual_MiniProbe_Minus(end - estimation_length +1 : end), ChLength);
Chest_Minus = Chest_Minus(1,1:21).';

for ch_index = 1:21
    Interpolated_Channel(ch_index,:) = interp1([1 Data_Length], [Chest_Plus(ch_index) Chest_Minus(ch_index)], (1:Data_Length),'linear','extrap');
end

Interpolated_Channel(:,1:end-8) = Interpolated_Channel(:,9:end);

for index = 1:Data_Length
    
    if mod(index-1,16) == 0
        [H H_herm s I_N I_N1_1 Hff Hff_herm sff Vff Hfb Hfb_herm] = Generate_H_Fractional(Interpolated_Channel(:,index),N*Oversample,N1*Oversample,N2*Oversample,Oversample);
        
        f_ff(index,:) = inv( Hff*Vff*Hff_herm + 1/(EsNoRatio)*I_N1_1 )*sff;
        f_ff_T = f_ff(index,:).';
        
        f_fb(index,:) = -Hfb_herm*f_ff_T;
        f_fb_T = f_fb(index,:).';
        
    else
        f_ff(index,:) = f_ff(index-1,:);
        f_ff_T = f_ff(index,:).';
        f_fb(index,:) = f_fb(index-1,:);
        f_fb_T = f_fb(index,:).';
    end
    
    
    zff = fliplr(IN_Frame_toEqualizer((index+N2-1)*Oversample+1:(index+N-1)*Oversample));
    zff_T = zff.';
    
    xn = fliplr(Hard_Decision_Symbols_Samples((index-1)*Oversample+1:(index+N2-1)*Oversample));
    
    xn_T = xn.';
    
    OUT_Symbols(index) = f_ff_T'*zff_T + f_fb_T'*xn_T;
    
    Hard_Decision_Symbols(N2+index+1) = 1*HF_Modulate(HF_Demodulate(OUT_Symbols(index),4800),4800);
    Hard_Decision_Symbols_Samples1=conv(upsample(Hard_Decision_Symbols,Oversample), HF_SRRC_TX_RX);
    Hard_Decision_Symbols_Samples = Hard_Decision_Symbols_Samples1(length(HF_SRRC)+Oversample:end-length(HF_SRRC)+1);
    
end

end





